<?php

class Errors
{
	function handler_error($errno, $errstr, $errfile, $errline)
	{
		switch ($errno)
		{
		    case E_USER_ERROR:
				$title = 'FATAL ERROR ['.$errno.'] '.$errstr;
				$msg =  'Erro fatal na linha '.$errline.' do arquivo '.$errfile;
				break;


		    case E_USER_WARNING:
		        $title = 'WARNING ['.$errno.'] '.$errstr;
				$msg =  'Erro fatal na linha '.$errline.' do arquivo '.$errfile;
				break;

		    case E_USER_NOTICE:
		        $title = 'NOTICE ['.$errno.'] '.$errstr;
				$msg =  'Erro fatal na linha '.$errline.' do arquivo '.$errfile;
				break;

		    default:
		        $title = 'UNKNOW TYPE ERROR ['.$errno.'] '.$errstr;
				$msg =  'Erro fatal na linha '.$errline.' do arquivo '.$errfile;
				break;
	    }

		$dialog = new GtkDialog(
		    $title,
		    NULL,
		    Gtk::DIALOG_MODAL,
		    //Gtk::DIALOG_DESTROY_WITH_PARENT,
		    array(
		        Gtk::STOCK_OK, Gtk::RESPONSE_OK
		    )
		);

		$frame = new GtkFrame($title);
		$frame->set_border_width(10);
		$label = new GtkLabel($msg);
		$label->set_padding(10,10);
		$frame->add($label);
		$dialog->vbox->add($frame);
		$dialog->show_all();
		$result = $dialog->run();

		if ($result == Gtk::RESPONSE_OK)
		{
			$dialog->destroy();
			//exit;
		}
		return true;
	}

	static function dialog($msg, $title='Error')
	{		
		$dialog = new GtkDialog(
		    $title,
		    NULL,
		    Gtk::DIALOG_MODAL,
		    //Gtk::DIALOG_DESTROY_WITH_PARENT,
		    array(
		        Gtk::STOCK_OK, Gtk::RESPONSE_OK
		    )
		);

		$label = new GtkLabel($msg);
		$label->set_padding(30,30);
		$dialog->vbox->add($label);
		$dialog->show_all();
		$result = $dialog->run();

		if ($result == Gtk::RESPONSE_OK)
		{
			$dialog->destroy();
		}
	}	
	
	function trigger($msg,$type)
	{
		trigger_error($msg,$type);
	}
}

?>
